package org.hry.netty.watermark;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

public class NettyServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
       while (true) {
           boolean writable = ctx.channel().isWritable();
           if (writable) {
               // 可以写入数据
//               System.out.println("可以写入数据: " + writable);
               ctx.writeAndFlush("可以写入数据");
           } else {
               // 不可以写入数据
               System.out.println("不可以写入数据：" + writable);
               return;
           }
       }
    }

    @Override
    public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
        if (ctx.channel().isWritable()) {
            // 继续写
        } else{
            // 等待
        }
    }
}
